<!DOCTYPE html>
<link rel="stylesheet" href="/assets/css/admin.css" />
<link rel="stylesheet" href="/assets/css/admin.dark.css" />
<link rel="stylesheet" href="/pear/css/pear.css" />
<div style="padding: 16px;">
    <div class="layui-card">
        <div class="layui-card-body">
            <div class="layui-tab layui-tab-brief">
                <ul class="layui-tab-title">
                    <li class="layui-this">基本信息</li>
                    <li>安全设置</li>
                </ul>
                <div class="layui-tab-content" style="padding: 15px 0;">
                    <div class="layui-tab-item layui-show">
                        <form class="layui-form layui-form-pane" style="width: 400px;">
                            <input type="hidden" name="m" value="base">
                            <div class="layui-form-item">
                                <label class="layui-form-label">昵称</label>
                                <div class="layui-input-block">
                                    <input type="text" name="nickname" autocomplete="off" placeholder="请输入"
                                        lay-verify="required" class="layui-input" value="{$nickname}">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">头像</label>
                                <div class="layui-input-group">
                                    <input type="text" name="avatar" autocomplete="off" placeholder="请输入"
                                        lay-verify="required" class="layui-input" value="{$avatar}">
                                    <div class="layui-input-suffix">
                                        <img src="{$avatar}" data-title="头像" class="image" />
                                    </div>
                                    <div class="layui-input-suffix uploads">
                                        <a href="javascript:;" class="layui-btn ">
                                            <i class="layui-icon layui-icon-upload"></i>上传
                                        </a>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">邮箱</label>
                                <div class="layui-input-block">
                                    <input type="text" name="email" autocomplete="off" placeholder="请输入"
                                        class="layui-input" value="{$email}">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">电话</label>
                                <div class="layui-input-block">
                                    <input type="text" name="mobile" autocomplete="off" placeholder="请输入"
                                        class="layui-input" value="{$mobile}">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button type="submit" class="layui-btn layui-btn-md" lay-submit
                                        lay-filter="form-submit">
                                        提交
                                    </button>
                                </div>
                            </div>
                        </form>
                    </div>
                    <div class="layui-tab-item">
                        <form class="layui-form layui-form-pane" style="width: 400px;">
                            <input type="hidden" name="m" value="safety">
                            <div class="layui-form-item">
                                <label class="layui-form-label">原密码</label>
                                <div class="layui-input-block">
                                    <input type="password" name="oldPassword" autocomplete="off" placeholder="请输入"
                                        lay-verify="required" class="layui-input" lay-affix="eye" value="">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">新密码</label>
                                <div class="layui-input-block">
                                    <input type="password" name="newPassword" autocomplete="off" placeholder="请输入"
                                        lay-verify="required" class="layui-input" lay-affix="eye" value="">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">确认新密码</label>
                                <div class="layui-input-block">
                                    <input type="password" name="password_confirm" autocomplete="off" placeholder="请输入"
                                        lay-verify="required" class="layui-input" lay-affix="eye" value="">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button type="submit" class="layui-btn layui-btn-md" lay-submit
                                        lay-filter="form-submit">
                                        提交
                                    </button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="/layui/layui.js"></script>
<script src="/pear/pear.js"></script>
<script>
    layui.use(['common', 'jquery', 'form', 'layer'], function () {

        // 查看文件
        layui.common.openFiles(".image");
        // 附件上传
        layui.$(".uploads").on("click", function () {
            layui.common.openAssets(this, `{:route('admin.attachment.query')}`);
        })

        // 提交
        layui.form.on('submit(form-submit)', function (data) {
            let field = data.field; // 获取表单全部字段值
            let elemForm = data.form; // 获取当前表单域的 form 元素对象，若容器为 form 标签才会返回。

            if (typeof field.password_confirm != "undefined") {
                if (field.password_confirm != field.newPassword) {
                    layui.common.validate(layui.$(elemForm), "password_confirm", "两次密码不一致");
                    return false
                }
            }

            let load = layui.layer.load(0);
            layui.$.post("{:route('admin.config.info')}", field, function (res) {
                if (res.code == 1) {
                    layer.msg(res.msg, { icon: res.code }, function () {
                        location.reload();
                    });
                } else {
                    if (res.data != "") {
                        layui.common.validate(layui.$(elemForm), res.data, res.msg);
                    } else {
                        layui.layer.msg(res.msg, { icon: res.code });
                    }
                }
                layui.layer.close(load);
            })
            return false; // 阻止默认 form 跳转
        });
    })
</script>